﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace DELVE_GAME.ViewStructure
{
    class Sprite
    {
        private int imageWidth;
        private int imageHeight;
        private Texture2D spriteSheet;
        private int numImages;
        private int numCols;
        private int numRows;

        public Sprite(Texture2D texture)
        {
            this.spriteSheet = texture;
            Rectangle bounds = texture.Bounds;
            imageWidth = bounds.Width;
            imageHeight = bounds.Height;
            numImages = 1;
            numCols = 1;
            numRows = 1;
        }

        public Sprite(Texture2D texture, int width, int height, int imagesPerRow, int numImages)
        {
            this.spriteSheet = texture;
            imageWidth = width;
            imageHeight = height;
            this.numImages = numImages;
            numCols = imagesPerRow;
            numRows = numImages/imagesPerRow;
        }

        public void draw(SpriteBatch sb, int x, int y, int imageIndex, double scale, Color color)
        {
            imageIndex %= numImages;
            int col = imageIndex % numCols;
            int row = imageIndex / numCols;
            Rectangle src = new Rectangle(imageWidth * col, imageHeight * row, imageWidth, imageHeight);
            Rectangle dest = new Rectangle(x, y, (int)(imageWidth * scale), (int)(imageHeight * scale));
            sb.Begin();
            sb.Draw(spriteSheet, dest, src, color);
            sb.End();
        }

        public void draw(SpriteBatch sb, int x, int y, int imageIndex, double scaleX, double scaleY, Color color)
        {
            imageIndex %= numImages;
            int col = imageIndex % numCols;
            int row = imageIndex / numCols;
            Rectangle src = new Rectangle(imageWidth * col, imageHeight * row, imageWidth, imageHeight);
            Rectangle dest = new Rectangle(x, y, (int)(imageWidth * scaleX), (int)(imageHeight * scaleY));
            sb.Begin();
            sb.Draw(spriteSheet, dest, src, color);
            sb.End();
        }

        public int height()
        {
            return imageHeight;
        }

        public int width()
        {
            return imageWidth;
        }
    }
}
